package com.dev.bbs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dev.bbs.domain.BbsComment;
import com.dev.bbs.domain.BbsMentLike;
import com.dev.bbs.mapper.BbsCommentMapper;
import com.dev.bbs.service.IBbsCommentService;
import com.dev.bbs.service.IBbsMentLikeService;
import com.dev.common.utils.DateUtils;

/**
 * 帖子评论Service业务层处理
 * 
 * @author dev
 * @date 2019-09-23
 */
@Service
public class BbsCommentServiceImpl implements IBbsCommentService
{
    @Autowired
    private BbsCommentMapper    bbsCommentMapper;

    @Autowired
    private IBbsMentLikeService mentLikeService;

    /**
     * 查询帖子评论
     * 
     * @param mentId 帖子评论ID
     * @return 帖子评论
     */
    @Override
    public BbsComment selectBbsCommentById(Long mentId)
    {
        return bbsCommentMapper.selectByPrimaryKey(mentId);
    }

    /**
     * 查询帖子评论列表
     * 
     * @param bbsComment 帖子评论
     * @return 帖子评论
     */
    @Override
    public List<BbsComment> selectBbsCommentList(BbsComment bbsComment)
    {
        return bbsCommentMapper.selectBbsCommentList(bbsComment);
    }

    /**
     * 新增帖子评论
     * 
     * @param bbsComment 帖子评论
     * @return 结果
     */
    @Override
    public int insertBbsComment(BbsComment bbsComment)
    {
        bbsComment.setCreateTime(DateUtils.getNowDate());
        return bbsCommentMapper.insertSelective(bbsComment);
    }

    /**
     * 修改帖子评论
     * 
     * @param bbsComment 帖子评论
     * @return 结果
     */
    @Override
    public int updateBbsComment(BbsComment bbsComment)
    {
        bbsComment.setUpdateTime(DateUtils.getNowDate());
        return bbsCommentMapper.updateByPrimaryKeySelective(bbsComment);
    }

    /**
     * 删除帖子评论对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBbsCommentByIds(String ids)
    {
        return bbsCommentMapper.deleteByIds(ids);
    }

    /**
     * 删除帖子评论信息
     * 
     * @param mentId 帖子评论ID
     * @return 结果
     */
    public int deleteBbsCommentById(Long mentId)
    {
        return bbsCommentMapper.delete(new BbsComment().setMentId(mentId).setAccept(false));
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.dev.bbs.service.IBbsCommentService#like(java.lang.Long, long)
     */
    @Override
    public int like(Long mentId, long userId)
    {
        BbsMentLike bbsMentLike = new BbsMentLike().setMentId(mentId).setUserId(userId);
        if (mentLikeService.insertBbsMentLike(bbsMentLike) > 0)
        {
            return bbsCommentMapper.addLike(mentId);
        }
        return 0;
    }
}
